Getting Started

RStudio and Basic Quarto

October 27, 2023

RStudio Setup

  • Go to posit.co
  • Click on links to install R and RStudio
  • Install the Tidyverse group of packages from the console
  • Go to Tools>Global Options
    • Under Code, enable native pipe operator (|>)
    • Under Appearance, choose a theme
    • Configure panes
  • Install lorem add in (install.packages("lorem"))
  • Restart R Session (Session > Restart R)

Quarto Setup

  • Go to quarto.org
  • Select “Get Started”
  • Download and install Quarto CLI
  • Restart R session in RStudio

Project Oriented Workflow


  • Always start a document in a project folder
  • That way you don’t have to do setwd
  • Also can share easily with other people

Project Oriented Workflow

  • Go to File > New Project
  • Create a Quarto project folder
  • Open a Quarto quarto document
  • Render it
  • Change Quarto doc elements
    • Add text with lipsum
  • Explore reference
  • Add stuff to YAML
    • e.g. subtitle, author, date, theme, etc.
10:00

Add a Visualization

Add a Visualization


library(gganimate)
library(gapminder)

ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
  geom_point(alpha = 0.7, show.legend = FALSE) +
  scale_colour_manual(values = country_colors) +
  scale_size(range = c(2, 12)) +
  scale_x_log10() +
  facet_wrap(~continent) +
  labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
  transition_time(year) +
  ease_aes('linear')

Add a Visualization


library(gganimate)
library(gapminder)

ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
  geom_point(alpha = 0.7, show.legend = FALSE) +
  scale_colour_manual(values = country_colors) +
  scale_size(range = c(2, 12)) +
  scale_x_log10() +
  facet_wrap(~continent) +
  labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
  transition_time(year) +
  ease_aes('linear')

Publish HTML to Quarto Pub

  • Go to quartopub.com
  • Set up Quarto pub account
  • Look at guide for publishing on Quarto pub
  • With your Quarto pub account open:
    • Go to terminal in RStudio
    • Type quarto publish quarto pub
15:00

Making PDFs


  • Install tinytex
  • Type quarto install tinytex in terminal
  • Change document type in YAML header to pdf
  • Take animation out of your plot
  • Look at Quarto Reference and play with options

Other Document Types


  • Word (docx)
  • Typst (typst)
    • New scientific typesetting language
    • Many advantages over \(\LaTeX\) & Word
  • Revealjs

Revealjs Slides

  • Revealjs is an open source HTML presentation framework that is built on open web technologies like CSS and JavaScript
  • These slides are made with the revealjs format in Quarto
  • Like other Quarto documents, you can set all the formatting in the YAML header
  • But you can also customize individual slides

Execution Options (YAML)


YAML header with execution options for these slides…

---
title: Getting Started
subtitle: RStudio and Basic Quarto
date: today
date-format: long
footer: "[DataViz 2102 Website](https://dataviz-gwu.rocks)"
logo: images/dataviz-logo.png
format:
  revealjs:
    theme: [simple, custom.scss]
    transition: fade
    slide-number: true
    multiplex: true
execute:
  echo: false
  message: false
  warning: false
  freeze: auto
---

Execution Options (Code Chunk)


You can also set execution options for individual code chunks…

```{r}
#| label: code-chunk
#| echo: false
#| message: false
#| warning: false

2 + 2
```

Your Turn!


  • Try rendering your document as a revealjs slide deck
  • If you have added a lot of lorem ipsum, start a new document
  • Change the execution options in the YAML header
  • Then try changing them in the code chunk for your plot
10:00

Assignments


Coding Assignment 1 relates to the material we are covering today (through module 1.2)


Coding Assignment 2 relates to everything from module 2 (on data viz)


Final Project asks you to make a Quarto document or presentation with some original visualizations. Be creative!